package br.edu.bdd.machado.controller;

import java.util.Date;
import java.util.List;

import org.hibernate.SessionFactory;

import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.util.extjs.ExtJSJson;
import br.com.caelum.vraptor.view.Results;
import br.edu.bdd.machado.dao.EditoraDAO;
import br.edu.bdd.machado.entity.*;

@Resource
public class EditoraController {
	
	private Result result;
	private EditoraDAO editoradao;
	public EditoraController(EditoraDAO editoradao, Result result)
	{
		this.editoradao= editoradao;
		this.result = result;
	}
	
	@Post
	@Path("/salvar/editora")
	public void salvar(Editora editora)
	{	
		
		editoradao.Salvar(editora);
		
	}
	
	@Path("/editora/listar/dados.json")
	public void listar()
	{
		
		
		result.use(ExtJSJson.class).from(editoradao.Listar()).serialize();
		
		
	}
	
	@Path("editora/listar/{textodepesquisa}/dados.json")
	public void listarPesquisa(String textodepesquisa)
	{
		result.use(ExtJSJson.class).from(editoradao.PesquisaEditora(textodepesquisa)).serialize();
	}
	
	@Path("/editora/apagar/{id}")
		public void Apagar(int id)
	{
		
		editoradao.Apagar(editoradao.carregaEditora(id));
	}

}
